package com.hna.eking.Redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisUtils {
	private String HostAddress = "localhost";
	private int Port = 6379;
	private int MaxActive = 10;
	private int MaxIdle = 5;
	private int MaxWait = 10001;
	private JedisPoolConfig config;
	private Jedis jedis;
	private JedisPool jedisPool;
	private static final Logger logger = LoggerFactory.getLogger(RedisUtils.class); 
	public RedisUtils(String HostAddress, int Port) {
		this.HostAddress = HostAddress;
		this.Port = Port;
	}

	public void InitJRedis() {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(MaxActive);
		config.setMaxIdle(MaxIdle);
		config.setMaxWaitMillis(MaxIdle);
		
//		jedisPool = new JedisPool(config, HostAddress, Port);
//		jedis = jedisPool.getResource(); 
		logger.error(HostAddress + Port);
		jedis = new Jedis(HostAddress, Port);
		if(jedis == null){
			System.out.println("error new");
		}
		
		
	}
	
	public boolean IsConnect(){
		return jedis.isConnected();
	}
	public String RedisPing(){
		return jedis.ping();
	}
	public void CloseRedis(){
		jedis.close();
//		jedisPool.close();
	}
	
	public void SetStrContext(String Key, String Value){
		jedis.set(Key, Value);
	}
	
	public String GetStrContext(String Key){
		String Ret = "";
		return Ret = jedis.get(Key);
	}
	public String getHostAddress() {
		return HostAddress;
	}
	public void DelStrKey(String Key){
		jedis.del(Key);
	}
	
	public void setHostAddress(String hostAddress) {
		HostAddress = hostAddress;
	}

	public int getPort() {
		return Port;
	}

	public void setPort(int port) {
		Port = port;
	}

	public int getMaxActive() {
		return MaxActive;
	}

	public void setMaxActive(int maxActive) {
		MaxActive = maxActive;
	}

	public int getMaxIdle() {
		return MaxIdle;
	}

	public void setMaxIdle(int maxIdle) {
		MaxIdle = maxIdle;
	}

	public int getMaxWait() {
		return MaxWait;
	}

	public void setMaxWait(int maxWait) {
		MaxWait = maxWait;
	}
}
